﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class UserControl_ucMenuCategory : System.Web.UI.UserControl
{
    TblMenuHorizDAO menu = new TblMenuHorizDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                LoadMenuItems();
            }
            catch (Exception ex)
            {
                Session[Global.SESSION_ERROR] = ex;
                Response.Redirect("~/Error.aspx", true);
            }
        }
    }
    private void LoadMenuItems()
    {
        try
        {
            string name = Global.GetPageName(Request.ServerVariables["SCRIPT_NAME"].ToString());
            int IDGroup = 1;

            if (name == "Products.aspx")
                IDGroup = 1;
            if (name == "ProductsCN.aspx")
                IDGroup = 3;
            lstCategories.DataSource = menu.GetMenuHoriz(IDGroup);
            lstCategories.DataBind();
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);

        }

    }

    protected void lstCategories_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        //if (e.Item.ItemType == ListViewItemType.DataItem)
        //{
        //    HyperLink lnk = (HyperLink)e.Item.FindControl("hyplink");

        //    //Get the item object.
        //    ListViewDataItem dataItem = (ListViewDataItem)e.Item;
        //    TblMenuHoriz menu = (TblMenuHoriz)dataItem.DataItem;
        //    string url = menu.NavigationUrl;

        //    url = url.Replace("~/", "");
        //    lnk.Attributes.Add("onclick", "UpdateParentsLogin('" + url + "') ");

        //}
    }
}
